﻿using UnityEngine;
namespace Demo
{
    public class GameManager : SingletonBehaviour<GameManager>
    {
        LuaManager luaMgr;
        /// <summary>
        /// 初始化游戏管理器
        /// </summary>
        void Awake()
        {
            DontDestroyOnLoad(gameObject);  //防止销毁自己
            //1. to do 资源检测、释放
            //2. 更新资源 如：lua 脚本
            OnResourceInited();
        }

        /// <summary>
        /// 资源初始化结束
        /// </summary>
        public void OnResourceInited()
        {
            // 1. 初始化assetbundle,
            Invoke("OnInitialize", .1f);
        }

        private void OnInitialize()
        {
            luaMgr = gameObject.GetComponent<LuaManager>();
            luaMgr.InitStart();
        }

        private void Update()
        {
         EventDispatcher.Instance.DispatchEvent(CommonEventType.Update);
        }

        private void FixedUpdate()
        {
            EventDispatcher.Instance.DispatchEvent(CommonEventType.FixedUpdate);
        }

        private void LateUpdate()
        {
            EventDispatcher.Instance.DispatchEvent(CommonEventType.LateUpdate);
        }

        public void OnGUI()
        {
            EventDispatcher.Instance.DispatchEvent(CommonEventType.OnGUI);
        }
    }
}
